<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <style>
        #div1{
            width: 300px;
            height:300px;
            background: red;
            opacity: 0.3;
            filter: alpha(opacity:30);
        }
    </style>
</head>
<body>
  <div id="div1"></div>
  <button id="btn">改变透明度</button>
  <script>
      var oDiv= document.getElementById("div1");
      var btn = document.getElementById('btn');
      var timer = null;
      var alpha = 30;

      oDiv.onmouseover = function () {
          startMove(100);
      };
      oDiv.onmouseout = function () {
          startMove(30);
      };

      function startMove(iTarget) {
          clearInterval(timer);
         timer = setInterval(function () {
             var speed = 0;

             if (alpha<iTarget){
                 speed=1
             }
             else {
                 speed=-1
             }

             if(alpha == iTarget){
                 clearInterval(timer)
             }
             else {
                 alpha+=speed;
                 oDiv.style.filter = 'alpha(opcity:'+alpha+')';
                 oDiv.style.opacity = alpha/100;
             }
         },30)
      }

  </script>
</body>
</html>